package converters

import (
	protos "goim-pro/api/protos/salty"
	"goim-pro/internal/app/models"
)

func ConvertSearchResult2Proto(users []models.User, contacts []models.Contact, groups []models.Group) (searchResults []*protos.SearchResult) {
	if users != nil {
		for _, user := range users {
			result := &protos.SearchResult{
				ResultType: protos.SearchType_USER,
				Result: &protos.SearchResult_UserResult{
					UserResult: ConvertEntity2ProtoForUserProfile(user),
				},
			}
			searchResults = append(searchResults, result)
		}
	}

	if contacts != nil {
		for _, contact := range contacts {
			result := &protos.SearchResult{
				ResultType: protos.SearchType_CONTACT,
				Result:     &protos.SearchResult_ContactResult{ContactResult: ConvertContactEntity2Proto(contact)},
			}
			searchResults = append(searchResults, result)
		}
	}

	if groups != nil {
		for _, group := range groups {
			result := &protos.SearchResult{
				ResultType: protos.SearchType_GROUP,
				Result:     &protos.SearchResult_GroupResult{GroupResult: ConvertEntity2ProtoForGroupProfile(group)}, //TODO:
			}
			searchResults = append(searchResults, result)
		}
	}

	return searchResults
}
